<template>
  <div class="content_center">
    <div class="bcg">
      <img src="../assets/u65.png" class="img_position" />
      <span class="topic">师范英语口语情景应答虚拟仿真实验</span>
      <span class="advice_mini">建议用户使用谷歌、火狐、微软Edge浏览器</span>
      <div style="display: flex;width: 100%;flex-direction: row-reverse;margin-top: 130px;">
        <LoginBox class="box_postion"></LoginBox>
      </div>
    </div>
  </div>
</template>

<script>
import LoginBox from '../components/login/LoginBox.vue'
import RApi from '../api/ExpRecord.js'
export default {
  //todo
  data () {
    return {}
  },
  components: {
    LoginBox
  },
  methods: {
    strat () {
      this.axios
        .post(RApi.add, {
          params: 1,
          username: this.$store.state.user.username,
          school: this.$store.state.user.school,
          experimentName: '分散实验',
          courseName: '	电商小件商品快速拣货决策虚拟仿真实验'
        })
        .then(res => {
          if (res.data.status == 0) {
            localStorage.setItem('exId', res.data.data) //实验记录Id
            localStorage.setItem('userId', this.$store.state.user.id)
            localStorage.setItem('school', this.$store.state.user.school)
            localStorage.setItem('username', this.$store.state.user.username)
            localStorage.setItem('group', '个人')
            // localStorage.setItem("teacher", row.username);
            localStorage.setItem('experimentName', '分散实验')
          }
          // window.location.href = "/zsd/webgl/";
          this.$router.push({ name: 'mainLayout' })
        })
    }
  },
  mounted () {
    var href = window.location.href
    window.console.log('href' + href)
    var startIndex = href.indexOf('?token=')
    // window.console.log(startIndex);
    var acture = startIndex + '?token='.length
    // window.console.log(acture);
    var lastIndex = href.indexOf('#/')
    var token = href.substr(acture, lastIndex - acture)
    // window.console.log(token);
    if (startIndex != -1) {
      window.console.log(token)

      //调用接口。获取token。
      //this.$store.commit("resetToken", token);  --->这里一定要是新token。
      this.axios.post('/zsd/user/ilab/login', { token: token }).then(res => {
        let restoken = res.data.data
        this.$store.commit('resetToken', restoken)
        this.strat()
      })
    } else {
      window.console.log('未发现token')
    }
  }
}
</script>

<style scope>
body {
  height: 100%;
  background: url("../assets/intro-bg.jpg") no-repeat fixed;
  background-size: 100% 100%;
}
.bcg {
  width: 100%;
  height: 100%;
}
.content_center {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
}
.img_position {
  position: relative;
  width: 420px;
  left: 50px;
  top: 50px;
}
.topic {
  color: white;
  position: absolute;
  top: 380px;
  left: 50px;
  width: 50%;
  font-size: 40px;
  font-weight: 600;
}
.box_postion {
  margin-right: 150px;
}
.advice_mini {
  position: absolute;
  top: 446px;
  left: 50px;
  color: white;
  font-size: 25px;
}
</style>
